package com.example.day09d_1;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.fragment.app.Fragment;

import io.reactivex.annotations.NonNull;


/**
 * A simple {@link Fragment} subclass.
 */
public class WebviewFragment extends Fragment {

    boolean muserVisibleHint;
    private WebView mWeb;

    public WebviewFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_blank, null);
        initView(view);
        return view;
    }

    private void initView(@NonNull final View itemView) {
        mWeb = (WebView) itemView.findViewById(R.id.web);



    }
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        if (!muserVisibleHint && isVisibleToUser) {
            mWeb.loadUrl("http://www.baidu.com");
            mWeb.setWebViewClient(new WebViewClient());
            muserVisibleHint=true;
        }
    }

}
